package com._520it.wms.query;

import lombok.Data;

import java.util.Collections;
import java.util.List;

/**
 * Created by Jon on 2017/11/1.
 */
//分页条的信息
@Data
public class PageResult {
     //用户传递的信息
         private int currentPage;//当前页
         private int pageSize;//每页显示的记录数

         //通过SQL查询的
         private List<?> list;//满足条件的结果集
         private int totalCount;//满足条件的总记录数
         //三个计算
         private int prevPage;//上一页
         private int nextPage;//下一页
         private int totalPage;//总页数
         //没有结果集时
         public PageResult(int currentPage,int pageSize) {
             this(currentPage, pageSize, Collections.EMPTY_LIST, 0);
         }
         public PageResult(int currentPage, int pageSize, List<?> list,
                           int totalCount) {
             this.currentPage = currentPage;
             this.pageSize = pageSize;
             this.list = list;
             this.totalCount = totalCount;
             //计算三个值
             this.totalPage = this.totalCount % this.pageSize == 0 ?
                     this.totalCount / this.pageSize :
                     this.totalCount / this.pageSize + 1;
             this.prevPage = this.currentPage - 1 >= 1 ? this.currentPage - 1 : 1;
             this.nextPage = this.currentPage + 1 <= this.totalPage ?
                     this.currentPage + 1 : this.totalPage;
         }
}
